From: Giovanni Campagna Date: Sun, 19 Jan 2014 17:46:36 +0000 (+0100) Subject: Introduce support for desktop actions in the dash X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~2896 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=7e27afb645560135a55763b06c94d74193a25762;p=gnome-shell.git Introduce support for desktop actions in the dash Using the new list_actions() API in Gio, add entries for static actions specified in .desktop files in the right-click app menus, in the dash, app well and search. https://bugzilla.gnome.org/show_bug.cgi?id=669603 --- diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 47ff948ab..3a2125aaa 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -1501,7 +1501,18 @@ const AppIconMenu = new Lang.Class({ this._source.app.open_new_window(-1); this.emit('activate-window', null); })); + this._appendSeparator(); + let appInfo = this._source.app.get_app_info(); + let actions = appInfo.list_actions(); + for (let i = 0; i < actions.length; i++) { + let action = actions[i]; + let item = this._appendMenuItem(appInfo.get_action_name(action)); + item.connect('activate', Lang.bind(this, function(emitter, event) { + this._source.app.launch_action(action, event.get_time(), -1); + this.emit('activate-window', null); + })); + } this._appendSeparator(); let isFavorite = AppFavorites.getAppFavorites().isFavorite(this._source.app.get_id()); diff --git a/src/shell-app.c b/src/shell-app.c index 07fe94382..283bd53e4 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -1185,6 +1185,32 @@ app_child_setup (gpointer user_data) } #endif +static GAppLaunchContext * +make_launch_context (guint timestamp, + int workspace) +{ + GdkAppLaunchContext *context; + ShellGlobal *global; + MetaScreen *screen; + GdkDisplay *gdisplay; + + global = shell_global_get (); + screen = shell_global_get_screen (global); + gdisplay = gdk_screen_get_display (shell_global_get_gdk_screen (global)); + + if (timestamp == 0) + timestamp = shell_global_get_current_time (global); + + if (workspace < 0) + workspace = meta_screen_get_active_workspace_index (screen); + + context = gdk_display_get_app_launch_context (gdisplay); + gdk_app_launch_context_set_timestamp (context, timestamp); + gdk_app_launch_context_set_desktop (context, workspace); + + return G_APP_LAUNCH_CONTEXT (context); +} + /** * shell_app_launch: * @timestamp: Event timestamp, or 0 for current event timestamp @@ -1197,11 +1223,8 @@ shell_app_launch (ShellApp *app, int workspace, GError **error) { - GdkAppLaunchContext *context; + GAppLaunchContext *context; gboolean ret; - ShellGlobal *global; - MetaScreen *screen; - GdkDisplay *gdisplay; if (app->info == NULL) { @@ -1210,22 +1233,10 @@ shell_app_launch (ShellApp *app, return TRUE; } - global = shell_global_get (); - screen = shell_global_get_screen (global); - gdisplay = gdk_screen_get_display (shell_global_get_gdk_screen (global)); - - if (timestamp == 0) - timestamp = shell_global_get_current_time (global); - - if (workspace < 0) - workspace = meta_screen_get_active_workspace_index (screen); - - context = gdk_display_get_app_launch_context (gdisplay); - gdk_app_launch_context_set_timestamp (context, timestamp); - gdk_app_launch_context_set_desktop (context, workspace); + context = make_launch_context (timestamp, workspace), ret = g_desktop_app_info_launch_uris_as_manager (app->info, NULL, - G_APP_LAUNCH_CONTEXT (context), + context, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, #ifdef HAVE_SYSTEMD app_child_setup, (gpointer)shell_app_get_id (app), @@ -1239,6 +1250,30 @@ shell_app_launch (ShellApp *app, return ret; } +/** + * shell_app_launch_action: + * @app: the #ShellApp + * @action_name: the name of the action to launch (as obtained by + * g_desktop_app_info_list_actions()) + * @timestamp: Event timestamp, or 0 for current event timestamp + * @workspace: Start on this workspace, or -1 for default + */ +void +shell_app_launch_action (ShellApp *app, + const char *action_name, + guint timestamp, + int workspace) +{ + GAppLaunchContext *context; + + context = make_launch_context (timestamp, workspace); + + g_desktop_app_info_launch_action (G_DESKTOP_APP_INFO (app->info), + action_name, context); + + g_object_unref (context); +} + /** * shell_app_get_app_info: * @app: a #ShellApp diff --git a/src/shell-app.h b/src/shell-app.h index dabf8bb6e..120385c4e 100644 --- a/src/shell-app.h +++ b/src/shell-app.h @@ -74,6 +74,11 @@ gboolean shell_app_launch (ShellApp *app, int workspace, GError **error); +void shell_app_launch_action (ShellApp *app, + const char *action_name, + guint timestamp, + int workspace); + int shell_app_compare_by_name (ShellApp *app, ShellApp *other); int shell_app_compare (ShellApp *app, ShellApp *other);